﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ConvergensDominoConnector;


namespace CDCOSDH
{
    public partial class MyActiveCases : Form
    {
        private string sdhName;
        private string viewName;

        public List<string> selectedRow = new List<string>(10);

        public MyActiveCases(string sdhName, string viewName)
        {
            InitializeComponent();

            this.sdhName = sdhName;
            this.viewName = viewName;
            this.Text = "Mine aktive sager i " + this.sdhName + " SDH";

            this.dataTableMyActiveCases.Select();
        }

        private void MyActiveCases_Load(object sender, EventArgs e)
        {
            try
            {
                this.dataTableMyActiveCases.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
                this.dataTableMyActiveCases.RowHeadersVisible = false;

                this.dataTableMyActiveCases.DataSource = DominoConnector.Default.GetMyActiveCases(this.viewName, this.sdhName);
                //this.dataTableMyActiveCases.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
                this.dataTableMyActiveCases.Columns["UNID"].Visible = false;

                foreach (DataGridViewRow row in this.dataTableMyActiveCases.Rows)
                {
                    DateTime dt = Convert.ToDateTime(row.Cells[2].Value);
                    row.Cells[2].Value = dt.ToShortDateString();
                }

                this.dataTableMyActiveCases.Columns[0].Width = 98;
                this.dataTableMyActiveCases.Columns[1].Width = 567;
                this.dataTableMyActiveCases.Columns[2].Width = 83;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            List<string> selectedRow = new List<string>(10);

            foreach (DataGridViewRow row in this.dataTableMyActiveCases.SelectedRows)
            {
                selectedRow.Add(row.Cells[0].Value.ToString());
                selectedRow.Add(row.Cells[1].Value.ToString());
                selectedRow.Add(row.Cells[3].Value.ToString());
            }

            this.selectedRow.AddRange(selectedRow);
            selectedRow = null;
            this.DialogResult = DialogResult.OK;
        }

        private void btnCnl_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void dataTableMyActiveCases_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            List<string> selectedRow = new List<string>(10);

            foreach (DataGridViewRow row in this.dataTableMyActiveCases.SelectedRows)
            {
                selectedRow.Add(row.Cells[0].Value.ToString());
                selectedRow.Add(row.Cells[1].Value.ToString());
                selectedRow.Add(row.Cells[3].Value.ToString());
            }

            this.selectedRow.AddRange(selectedRow);
            selectedRow = null;
            this.DialogResult = DialogResult.OK;
        }

        private void dataTableMyActiveCases_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.dataTableMyActiveCases.SelectedRows.Count == 0)
            {
                return;
            }

            if (e.KeyCode == Keys.Enter)
            {
                List<string> selectedRow = new List<string>(10);
                foreach (DataGridViewRow row in this.dataTableMyActiveCases.SelectedRows)
                {
                    selectedRow.Add(row.Cells[0].Value.ToString());
                    selectedRow.Add(row.Cells[1].Value.ToString());
                    selectedRow.Add(row.Cells[3].Value.ToString());
                }

                this.selectedRow.AddRange(selectedRow);
                selectedRow = null;
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
